<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2017 河源市卓锐科技有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------
// | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------

namespace app\goods\model;

use think\Model;

/**
 * 价格
 */
class Price extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = '__GOODS_PRICE__';

    // 自动写入时间戳
    protected $autoWriteTimestamp = true;

    //根据各种价格策略返回最终商品价格 sky
    public function getGoodsPrice($goods_id,$level_id)
    {
        $priceInfo = $this->getGoodsPriceInfo($goods_id);
        $price = isset($priceInfo[$level_id]) ? $priceInfo[$level_id]['money'] : 0;
        //dump($priceInfo);
        return $price;
    }

    //按客户等级返回价格信息 sky del
    public function getGoodsPriceInfoByLevel($level_id,$goods_id)
    {
        $map['levelid'] = $level_id;
        $map['skuid'] = $goods_id;
        $rs = $this->where($map)->find();
        return $rs ? $rs->toArray() : array();
    }

    //商品不同客户等级价格 sky
    public function getGoodsPriceInfo($goods_id)
    {
        $map['skuid'] = $goods_id;
        $list = $this->where($map)->select();
        $data = array();
        foreach($list as $r)
        {
            $data[$r['levelid']] = $r->getData();
        }
        return $data;
    }
}